package com.swgk.core.util;
import android.util.Log;

/**
 * 屏蔽多次点击
 */
public class ClickUtils {
    //2次点击的间隔时间，单位ms
    private final static long SPACE_TIME = 1000;
    private static long SPACE_TIMES;
    private static long lastClickTime;

    public static void setSpaceTimes(long spaceTimes) {
        SPACE_TIMES = spaceTimes;
    }

    public synchronized static boolean isDoubleClick() {
        long currentTime = System.currentTimeMillis();
        boolean isClick;
        long dif= currentTime - lastClickTime;
        isClick = dif <= SPACE_TIME;
        lastClickTime = currentTime;
        return isClick;
    }
    public synchronized static boolean isDoubleClick2() {
        long currentTime = System.currentTimeMillis();
        boolean isClick;
        long dif= currentTime - lastClickTime;
        if(SPACE_TIMES==0){
            SPACE_TIMES=SPACE_TIME;
        }
        isClick = dif <= SPACE_TIMES;
        Log.e("diftime:",""+dif);
        lastClickTime = currentTime;
        return isClick;
    }

    public static boolean isFastClick() {
        boolean flag = false;
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= 300) {
            flag = true;
            //点击生效后才把值给覆盖点，不然一直点击这个按钮会一致不生效
            lastClickTime = curClickTime;
        }
        return flag;
    }
}
